package com.techsoul.module.order.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.techsoul.common.core.constant.ApiConstants;
import com.techsoul.common.core.exception.ExcelException;
import com.techsoul.common.core.exception.ParamException;
import com.techsoul.common.core.pojo.vo.UserVo;
import com.techsoul.common.core.util.ServletUtils;
import com.techsoul.common.core.util.bean.BeanUtils;
import com.techsoul.common.core.util.collection.ListUtils;
import com.techsoul.common.core.util.id.IdWorker;
import com.techsoul.common.core.util.lang.DateUtils;
import com.techsoul.common.core.util.lang.NumberUtils;
import com.techsoul.common.core.util.lang.StringUtils;
import com.techsoul.common.core.util.poi.ExcelExport;
import com.techsoul.common.core.util.poi.ExcelImport;
import com.techsoul.common.security.service.TokenService;
import com.techsoul.module.basic.mapper.StoreMapper;
import com.techsoul.module.basic.pojo.vo.CustomerVo;
import com.techsoul.module.basic.pojo.vo.StoreVo;
import com.techsoul.module.basic.service.ICustomerService;
import com.techsoul.module.order.enmus.ReturnOrderStatusEnum;
import com.techsoul.module.order.enmus.SalesOrderSourceEnum;
import com.techsoul.module.order.enmus.SalesOrderStatusEnum;
import com.techsoul.module.order.enmus.SalesOrderTypeEnum;
import com.techsoul.module.order.mapper.ReturnOrderItemMapper;
import com.techsoul.module.order.mapper.ReturnOrderMapper;
import com.techsoul.module.order.mapper.SalesOrderItemMapper;
import com.techsoul.module.order.pojo.entity.ReturnOrder;
import com.techsoul.module.order.pojo.entity.ReturnOrderItem;
import com.techsoul.module.order.pojo.entity.SalesOrder;
import com.techsoul.module.order.pojo.entity.SalesOrderItem;
import com.techsoul.module.order.pojo.param.ReturnOrderItemSaveParam;
import com.techsoul.module.order.pojo.param.ReturnOrderItemSearchParam;
import com.techsoul.module.order.pojo.vo.ReturnOrderItemVo;
import com.techsoul.module.order.pojo.vo.ReturnOrderVo;
import com.techsoul.module.order.pojo.vo.SalesOrderItemVo;
import com.techsoul.module.order.service.IReturnOrderItemService;
import com.techsoul.module.pms.pojo.vo.CustGoodsMapVo;
import com.techsoul.module.system.enmus.ErrorType;
import com.techsoul.module.system.mapper.OperationLogMapper;
import com.techsoul.module.system.pojo.entity.OperationLog;
import com.techsoul.module.system.service.IConfigService;
import com.techsoul.module.system.service.IGeneralSeqService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 退货单明细 Service实现
 *
 * @author liuen
 * @date 2020-12-07
 */

@Slf4j
@Service
@Transactional(readOnly = true)
public class ReturnOrderItemServiceImpl implements IReturnOrderItemService {

    @Autowired
    private IdWorker idWorker;

    @Autowired
    private ReturnOrderItemMapper mapper;
    @Autowired
    private IConfigService configService;
    @Autowired
    private ReturnOrderMapper returnorderMapper;
    @Autowired
    private SalesOrderItemMapper salesOrderItemmapper;

    @Autowired
    private ICustomerService iCustomerService;

    @Autowired
    private TokenService tokenService;
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private OperationLogMapper operationLogMapper;

    @Autowired
    private IGeneralSeqService generalSeqService;
    /**
     * 新增
     * @param params
     * @return
     */
    @Transactional(readOnly = false)
    @Override
    public String insert(ReturnOrderItemSaveParam params) {
        UserVo user = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        ReturnOrderItem entity = new ReturnOrderItem();
        BeanUtils.copyProperties(params, entity);
        entity.setId(idWorker.nextId() + "").preInsert(user.getId());
        this.mapper.insert(entity);
        return entity.getId();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Transactional(readOnly = false)
    @Override
    public Integer delete(String id) {
        return this.mapper.deleteById(id);
    }

    /**
     * 批量删除
     * @param idList
     */
    @Transactional(readOnly = false)
    @Override
    public Integer batchDelete(List<String> idList) {
        if (ListUtils.isNotEmpty(idList)) {
            return this.mapper.deleteBatchIds(idList);
        } else {
            return 0;
        }
    }

    /**
     * 修改
     * @param id
     * @param params
     * @return
     */
    @Transactional(readOnly = false)
    @Override
    public Integer update(String id, ReturnOrderItemSaveParam params) {
        UserVo user = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        ReturnOrderItem entityFromDb = this.mapper.selectById(id);
        if (entityFromDb == null) {
            throw new ParamException("id=" + id);
        }
        BeanUtils.copyProperties(params, entityFromDb);
        entityFromDb.preUpdate(user.getId());
        return this.mapper.updateById(entityFromDb);
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @Override
    public ReturnOrderItemVo findById(String id) {
        return this.mapper.findById(id);
    }

    @Override
    public List<ReturnOrderItemVo> findByCustReturnOrderItemNo(String custReturnOrderItemNo) {
        return this.mapper.findByCustReturnOrderItemNo(custReturnOrderItemNo);
    }

    /**
     * 列表
     * @param params
     * @return
     */
    @Override
    public List<ReturnOrderItemVo> findAll(ReturnOrderItemSearchParam params) {
        return this.mapper.findAll(params);
    }

    /**
     * 列表-分页
     * @param params
     * @param current
     * @param pageSize
     * @return
     */
    @Override
    public IPage<ReturnOrderItemVo> findAll(ReturnOrderItemSearchParam params, Integer current, Integer pageSize) {
        return this.mapper.findAll(new Page<>(current, pageSize), params);
    }
    /**
     * 导入模板
     */
    @Override
    public String importTemplate() {
        String baseDir = configService.findByConfigKey("project.attachment.baseDir");
        String baseUrl = configService.findByConfigKey("project.attachment.baseUrl");
        String fileName = "导入模板-退单-批量导入.xlsx";
        try {
            new ExcelExport(null, ReturnOrderItemVo.class).writeFile(baseDir + fileName).close();
        } catch (Exception e) {
            log.error("生成退单导入模板失败", e);
            throw new ExcelException(e.getMessage());
        }
        return baseUrl + fileName;
    }
    /**
     * 导入
     * @param file
     * @return
     */
    @Transactional(readOnly = false)
    @Override
    public String importData(String customerNo, MultipartFile file) {
        List<ReturnOrderItemVo> dataList = null;
        UserVo user = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();
        CustomerVo customerVo = iCustomerService.findById(customerNo);

        int successNum = 0;
        int failureNum = 0;
        int logNum = 0;
        try {
            ExcelImport excelImport = new ExcelImport(file, 1, 0);
            dataList = excelImport.getDataList(ReturnOrderItemVo.class);
        } catch (Exception e) {
            log.error("获取数据信息失败!");
            throw new ExcelException("获取数据信息失败!");
        }
        if (ListUtils.isEmpty(dataList)) {
            throw new ExcelException("导入数据不能为空！");
        }

        if(dataList==null||dataList.size()==0){
            return "没有读取到数据";
        }
        ReturnOrderItemVo firstdata = (ReturnOrderItemVo)dataList.get(0);
        String custOrderNo ="";
        ReturnOrder newSalesOrder = null;
        int itemNo = 0;
        int line = 0;
        List<String> custOrderNos = new ArrayList<String>();
        for (ReturnOrderItemVo data : dataList) {
            data = this.removeSpecialChar(data);
            line++;
            // if(!data.getCustSalesOrderNo().equals(custOrderNo)){
            custOrderNo =data.getCustSalesOrderNo();
            if(!custOrderNos.contains(custOrderNo)){
                itemNo = 0;
                newSalesOrder = this.addNewReturnOrder(data,user,customerVo,line);
                if(newSalesOrder!=null){
                    //custOrderNo = data.getCustSalesOrderNo();
                    custOrderNos.add(custOrderNo);
                }else{
                    failureNum++;
                    logNum++;
                    continue;
                }
            }

            itemNo = itemNo++;
            if(newSalesOrder!=null){
                ReturnOrderItem returnOrderItem = this.addNewItem(newSalesOrder,data,user,itemNo,line);
                if(returnOrderItem!=null){
                    successNum++;
                }else{
                    failureNum++;
                    logNum++;
                    continue;
                }
            }



        }
        if (failureNum > 0) {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误清查日志");
            OperationLog operationLog =new OperationLog();
            operationLog.setOperationType(ErrorType.ORDERIMPORT.getStatusName());
            operationLog.setErrorMsg(failureMsg.toString());
            operationLog.setMethod("导入模板-原始订单-批量导入");
            operationLog.setLocation("第"+line+"行");
            operationLog.setId(idWorker.nextId() + "").preInsert(user.getId());
            if (user != null) {
                operationLog.setOperatorName(user.getUserName() + "(" + user.getNickName() + ")");
            }
            operationLogMapper.insert(operationLog);
            // throw new ExcelException(failureMsg.toString());
            return "操作有"+failureNum+"行输入异常，请看日志";
        } else {
            if(logNum>0){
                successMsg.insert(0, "恭喜您，操作成功！共 " + successNum + " 条，另有：" +logNum+ " 条数据不能正常导入，已写入日志");

            }else{
                successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");

            }
        }
        return successMsg.toString();
    }


    /**
     * 从mq导入
     * @param returnOrderItemVo
     */
    @Transactional(readOnly = false)
    @Override
    public String importOrderFromMq(ReturnOrderItemVo returnOrderItemVo,String customerNo) {
        UserVo user = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
        String failureMsg = " ";
        CustomerVo customerVo = iCustomerService.findByCode(customerNo);
        if(customerVo == null){
            OperationLog operationLog =new OperationLog();
            operationLog.setOperationType(ErrorType.ORDERIMPORT.getStatusName());
            operationLog.setErrorMsg("客户商城不存在");
            operationLog.setMethod("读取队列订单");
            operationLog.setId(idWorker.nextId() + "").preInsert(ApiConstants.DEFAULT_USER_ID);
            if (user != null) {
                operationLog.setOperatorName(user.getUserName() + "(" + user.getNickName() + ")");
            }
            operationLogMapper.insert(operationLog);
            return "客户商城不存在";
        }
        int successNum = 0;
        int failureNum = 0;
        int logNum = 0;

        returnOrderItemVo = this.removeSpecialChar(returnOrderItemVo);
        String  custSalesOrderItemNo =returnOrderItemVo.getCustSalesOrderItemNo();
        ReturnOrder newSalesRtOrder = this.addNewReturnOrder(returnOrderItemVo, null,customerVo,1);

        if (newSalesRtOrder == null) {
            failureMsg="很抱歉，导入失败！";
            OperationLog operationLog =new OperationLog();
            operationLog.setOperationType(ErrorType.ORDERIMPORT.getStatusName());
            operationLog.setErrorMsg(failureMsg.toString());
            operationLog.setMethod("读取队列订单");
            operationLog.setLocation("客户子订单号"+custSalesOrderItemNo);
            operationLog.setId(idWorker.nextId() + "").preInsert(ApiConstants.DEFAULT_USER_ID);
            if (user != null) {
                operationLog.setOperatorName(user.getUserName() + "(" + user.getNickName() + ")");
            }
            operationLogMapper.insert(operationLog);
            return failureMsg;

        }
        ReturnOrderItem salesOrderItem = this.addNewItem(newSalesRtOrder,returnOrderItemVo,null,1,1);
        if (salesOrderItem == null) {
            failureMsg="很抱歉，导入失败！";
            OperationLog operationLog =new OperationLog();
            operationLog.setOperationType(ErrorType.ORDERIMPORT.getStatusName());
            operationLog.setErrorMsg(failureMsg.toString());
            operationLog.setMethod("读取队列订单");
            operationLog.setLocation("客户子订单号"+custSalesOrderItemNo);
            operationLog.setId(idWorker.nextId() + "").preInsert(ApiConstants.DEFAULT_USER_ID);
            if (user != null) {
                operationLog.setOperatorName(user.getUserName() + "(" + user.getNickName() + ")");
            }
            operationLogMapper.insert(operationLog);
            return failureMsg;

        }

        return "success";
    }

    @Transactional(readOnly = false)
    @Override
    public ReturnOrder addNewReturnOrder(ReturnOrderItemVo salesOrderItemVo,UserVo user,CustomerVo customerVo,int line) {

        ReturnOrder salesRtOrder = new ReturnOrder();
        String importError = "";
        String errorFlag="N";

        String orderNo = this.generalSeqService.generateSeq("oms_rt_sales_order");
        salesRtOrder.setCustSalesOrderNo(salesOrderItemVo.getCustSalesOrderNo());
        salesRtOrder.setReturnOrderNo(orderNo);
        salesRtOrder.setMemberId(customerVo.getId());//退单人

        salesRtOrder.setStatus(salesOrderItemVo.getCustReturnOrderStatus());

        salesRtOrder.setReturnType(SalesOrderTypeEnum.BySku.getValue());

        List<ReturnOrderItemVo> returnOrderItemVoFromDbs = this.findByCustReturnOrderItemNo(salesOrderItemVo.getCustReturnOrderItemNo());
        if(returnOrderItemVoFromDbs != null&&returnOrderItemVoFromDbs.size()>0){
            OperationLog operationLog =new OperationLog();
            operationLog.setOperationType(ErrorType.ORDERIMPORT.getStatusName());
            operationLog.setErrorMsg("订单已经输入，不可重复输入 ");
            operationLog.setMethod("101");
            operationLog.setLocation(salesOrderItemVo.getCustReturnOrderItemNo());
            operationLog.setId(idWorker.nextId() + "").preInsert(user != null ? user.getId() : ApiConstants.DEFAULT_USER_ID);
            if (user != null) {
                operationLog.setOperatorName(user.getUserName() + "(" + user.getNickName() + ")");
            }
            operationLogMapper.insert(operationLog);
            if(!StringUtils.isNull(importError)){
                importError =
                        importError.concat(operationLog.getLocation().concat(operationLog.getErrorMsg()));
                salesRtOrder.setImportErrorMesg(importError);
                errorFlag="Y";
            }else{
                salesRtOrder.setImportErrorMesg(operationLog.getLocation().concat(operationLog.getErrorMsg()));
                errorFlag="Y";
            }
            salesRtOrder.setErrorCode("101");
        }
        salesRtOrder.setErrorFlag(errorFlag);

        salesRtOrder.setId(idWorker.nextId() + "").preInsert(user != null ? user.getId() : ApiConstants.DEFAULT_USER_ID);
        this.returnorderMapper.insert(salesRtOrder);

        return salesRtOrder;


    }
    @Transactional(readOnly = false)
    @Override
    public ReturnOrderItem addNewItem(ReturnOrder newSalesOrder, ReturnOrderItemVo data, UserVo user, int itemNo, int line){

        ReturnOrderItem salesOrderItem = new ReturnOrderItem();
        salesOrderItem.setErrorFlag(newSalesOrder.getErrorFlag());
        if(!StringUtils.isNull(newSalesOrder.getErrorCode())){
            salesOrderItem.setErrorCode(newSalesOrder.getErrorCode());
            if(newSalesOrder.getErrorCode().equals("101")){
                salesOrderItem.setErrorFlag("Y");
            }
        }

        BeanUtils.copyProperties(data, salesOrderItem);
        String errorMsg = newSalesOrder.getImportErrorMesg();
        String itemErrorMsg = "退单导入：";


        salesOrderItem.setReturnOrderId(newSalesOrder.getReturnOrderNo());
        salesOrderItem.setSalesOrderItemId(newSalesOrder.getId());
        String custOrderItemNo = data.getCustSalesOrderItemNo();
        if(!StringUtils.isNull(custOrderItemNo)) {
            if(custOrderItemNo.contains("SC")){
                custOrderItemNo = custOrderItemNo.substring(2);
            }
        }

        salesOrderItem.setCustSkuId(data.getCustSkuId());


        if(data.getQty()==null){
            if(!StringUtils.isNull(salesOrderItem.getErrorCode())){
                salesOrderItem.setErrorCode(salesOrderItem.getErrorCode().concat(";").concat("103"));
            }else{
                salesOrderItem.setErrorCode("103");
            }
            salesOrderItem.setErrorFlag("Y");
            salesOrderItem.setImportErrorMesg("销售件数为空;");
            salesOrderItem.setCustSalesOrderNo(data.getCustSalesOrderNo());
            this.genOperationLog(salesOrderItem,user);
            salesOrderItem.setStatus(ReturnOrderStatusEnum.NEWREC.getValue());
        }else if(String.valueOf(data.getQty()).contains(".")){
            if(!StringUtils.isNull(salesOrderItem.getErrorCode())){
                salesOrderItem.setErrorCode(salesOrderItem.getErrorCode().concat(";").concat("103"));
            }else{
                salesOrderItem.setErrorCode("103");
            }
            salesOrderItem.setErrorFlag("Y");
            salesOrderItem.setImportErrorMesg("销售件数不是大于0的整数;");
            salesOrderItem.setCustSalesOrderNo(data.getCustSalesOrderNo());
            this.genOperationLog(salesOrderItem,user);
            salesOrderItem.setStatus(ReturnOrderStatusEnum.NEWREC.getValue());
        }else if(data.getQty()<0) {
            if(!StringUtils.isNull(salesOrderItem.getErrorCode())){
                salesOrderItem.setErrorCode(salesOrderItem.getErrorCode().concat(";").concat("103"));
            }else{
                salesOrderItem.setErrorCode("103");
            }
            salesOrderItem.setErrorFlag("Y");
            salesOrderItem.setImportErrorMesg("销售件数不是大于0的整数;");
            salesOrderItem.setCustSalesOrderNo(data.getCustSalesOrderNo());
            this.genOperationLog(salesOrderItem,user);
            salesOrderItem.setStatus(ReturnOrderStatusEnum.NEWREC.getValue());
        }
        if(StringUtils.isNull(data.getCustSpuId())){
            //||StringUtils.isNull(data.getCustSkuId())
            if(!StringUtils.isNull(salesOrderItem.getErrorCode())){
                salesOrderItem.setErrorCode(salesOrderItem.getErrorCode().concat(";").concat("100"));
            }else{
                salesOrderItem.setErrorCode("100");
            }
            salesOrderItem.setErrorFlag("Y");
            itemErrorMsg = itemErrorMsg.concat("对方商品ID为空;");
            salesOrderItem.setCustSalesOrderNo(data.getCustSalesOrderNo());
            salesOrderItem.setImportErrorMesg(itemErrorMsg);
            this.genOperationLog(salesOrderItem,user);
            salesOrderItem.setStatus(ReturnOrderStatusEnum.NEWREC.getValue());
        }
        List<ReturnOrderItemVo> returnItems = this.mapper.findByCustReturnOrderItemNo(data.getCustReturnOrderItemNo());
        if(returnItems!=null&&returnItems.size()>0){
            if(!StringUtils.isNull(salesOrderItem.getErrorCode())){
                salesOrderItem.setErrorCode(salesOrderItem.getErrorCode().concat(";").concat("108"));
            }else{
                salesOrderItem.setErrorCode("108");
            }
            salesOrderItem.setErrorFlag("Y");
            itemErrorMsg = itemErrorMsg.concat("退单号相同的退单已导入;");
            salesOrderItem.setCustSalesOrderNo(data.getCustSalesOrderNo());
            this.genOperationLog(salesOrderItem,user);
            salesOrderItem.setImportErrorMesg(itemErrorMsg);
            salesOrderItem.setStatus(ReturnOrderStatusEnum.NEWREC.getValue());
        }

        List<ReturnOrderItemVo> nextreturnItems = this.mapper.findByCustSalesOrderItemNo(data.getCustSalesOrderItemNo(),data.getCustSkuId());
        if(returnItems!=null&&returnItems.size()>0){
            if(!StringUtils.isNull(salesOrderItem.getErrorCode())){
                salesOrderItem.setErrorCode(salesOrderItem.getErrorCode().concat(";").concat("109"));
            }else{
                salesOrderItem.setErrorCode("109");
            }
            salesOrderItem.setErrorFlag("Y");
            itemErrorMsg = itemErrorMsg.concat("子订单号和SKU相同的退单已经导入;");
            salesOrderItem.setCustSalesOrderNo(data.getCustSalesOrderNo());
            this.genOperationLog(salesOrderItem,user);
            salesOrderItem.setImportErrorMesg(itemErrorMsg);
            salesOrderItem.setStatus(ReturnOrderStatusEnum.NEWREC.getValue());
        }
        if(StringUtils.isNull(data.getLastUpdDt())){
            if(!StringUtils.isNull(salesOrderItem.getErrorCode())){
                salesOrderItem.setErrorCode(salesOrderItem.getErrorCode().concat(";").concat("111"));
            }else{
                salesOrderItem.setErrorCode("111");
            }
            salesOrderItem.setErrorFlag("Y");
            itemErrorMsg = itemErrorMsg.concat("无成功退款日期;");
            salesOrderItem.setCustSalesOrderNo(data.getCustSalesOrderNo());
            this.genOperationLog(salesOrderItem,user);
            salesOrderItem.setImportErrorMesg(itemErrorMsg);
            salesOrderItem.setStatus(ReturnOrderStatusEnum.NEWREC.getValue());
        }

        salesOrderItem.setId(idWorker.nextId() + "").preInsert(user != null ? user.getId() : ApiConstants.DEFAULT_USER_ID);
        if(StringUtils.isNull(salesOrderItem.getStatus())){
            salesOrderItem.setStatus(SalesOrderStatusEnum.NEWREC.getValue());
        }
        if(data.getBuyPrice()!=null&&data.getQty()!=null){
            Double tot = NumberUtils.mul(data.getBuyPrice(),data.getQty());
            salesOrderItem.setMoney(tot);
        }
        salesOrderItem.setImportErrorMesg(itemErrorMsg);
        if(StringUtils.isNull(salesOrderItem.getErrorFlag())){
            salesOrderItem.setErrorFlag("N");
        }
        salesOrderItem.setCustSalesOrderItemNo(custOrderItemNo);
        this.mapper.insert(salesOrderItem);
        return salesOrderItem;
    }

    @Transactional(readOnly = false)
    @Override
    public void genOperationLog(ReturnOrderItem data,UserVo user ) {
        OperationLog operationLog = new OperationLog();
        operationLog.setOperationType(ErrorType.ORDERIMPORT.getStatusName());
        String errormsg = " ";
        if(!StringUtils.isNull(data.getGenAccFailedReason())){
            errormsg = errormsg.concat(data.getGenAccFailedReason());
        }
        if(!StringUtils.isNull(data.getImportErrorMesg())){
            errormsg = errormsg.concat(data.getImportErrorMesg());
        }
        operationLog.setErrorMsg(errormsg);
        operationLog.setMethod(data.getErrorCode());
        operationLog.setLocation(data.getCustSalesOrderNo());
        operationLog.setId(idWorker.nextId() + "").preInsert(user != null ? user.getId() : ApiConstants.DEFAULT_USER_ID);
        if (user != null) {
            operationLog.setOperatorName(user.getUserName() + "(" + user.getNickName() + ")");
        }
        operationLogMapper.insert(operationLog);

    }
    @Override
    public ReturnOrderItemVo removeSpecialChar(ReturnOrderItemVo input){
        Pattern p =null;
        Matcher m = null;;
        String rt = "";


        //spu
        if(!StringUtils.isNull(input.getCustReturnOrderItemNo())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getCustReturnOrderItemNo());
            rt = m.replaceAll("");
            input.setCustReturnOrderItemNo(rt);
        }
        if(!StringUtils.isNull(input.getBuyerId())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getBuyerId());
            rt = m.replaceAll("");
            input.setBuyerId(rt);
        }
        if(!StringUtils.isNull(input.getLastUpdDt())) {
            p = Pattern.compile("\t");
            m = p.matcher(input.getLastUpdDt());
            rt = m.replaceAll("");
            input.setLastUpdDt(rt);
        }
        if(!StringUtils.isNull(input.getGoodsName())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getGoodsName());
            rt = m.replaceAll("");
            input.setGoodsName(rt);
        }
        if(!StringUtils.isNull(input.getConsigneeName())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getConsigneeName());
            rt = m.replaceAll("");
            input.setConsigneeName(rt);
        }
        if(!StringUtils.isNull(input.getCustReturnOrderStatus())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getCustReturnOrderStatus());
            rt = m.replaceAll("");
            input.setCustReturnOrderStatus(rt);
        }
        if(!StringUtils.isNull(input.getCustSalesOrderNo())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getCustSalesOrderNo());
            rt = m.replaceAll("");
            input.setCustSalesOrderNo(rt);
        }
        if(!StringUtils.isNull(input.getCustSalesOrderItemNo())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getCustSalesOrderItemNo());
            rt = m.replaceAll("");
            input.setCustSalesOrderItemNo(rt);
        }

        if(!StringUtils.isNull(input.getStoreName())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getStoreName());
            rt = m.replaceAll("");
            input.setStoreName(rt);
        }

        if(!StringUtils.isNull(input.getCustSkuId())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getCustSkuId());
            rt = m.replaceAll("");
            input.setCustSkuId(rt);
        }
        if(!StringUtils.isNull(input.getCustSpuId())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getCustSpuId());
            rt = m.replaceAll("");
            input.setCustSpuId(rt);
        }

        if(!StringUtils.isNull(input.getCategoryId())) {
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getCategoryId());
            rt = m.replaceAll("");
            input.setCategoryId(rt);
        }


        if(!StringUtils.isNull(input.getStoreName())){
            p = Pattern.compile("\\s*|\t|\r|\n");
            m = p.matcher(input.getStoreName());
            rt = m.replaceAll("");
            input.setStoreName(rt);
        }


        return input;
    }
}
